//
//  ViewController.m
//  testSwitch
//
//  Created by 赵正华 on 16/8/16.
//  Copyright © 2016年 赵正华. All rights reserved.
//

#import "ViewController.h"
#import "PAWFLoadingSwitch.h"

@interface ViewController ()

@property (nonatomic,strong)PAWFLoadingSwitch *loadSwitch;
@property (nonatomic,strong)UIActivityIndicatorView *indicatorView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blueColor];
    [self addLoadSwitch];
}

-(void)addLoadSwitch{
   
  // VPN控制开关   --默认为关闭状态
    _loadSwitch = [[PAWFLoadingSwitch alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 45.0f, 27.0f)];
    _loadSwitch.center = self.view.center;
    
    [self.view addSubview:_loadSwitch];
    
    [_loadSwitch handleSwithClick:^(PAWFLoadingSwitch *loadingSwitch, PAWFLoadingSwitchType curType) {
        NSString *statusString = @"";
        if (curType == PAWFLoadingSwitchOff)
        {
            statusString = @"未开启";
            [self vpnSwtichOffClicked];
        }
        else if (curType == PAWFLoadingSwitchOn)
        {
            statusString = @"已开启";
            [self vpnSwitchOnClicked];
        }
        else
        {
            statusString = @"开启中";
            [self vpnSwitchLoadingClicked];
        }
    }];
}
-(void)vpnSwtichOffClicked{
    _loadSwitch.switchType = PAWFLoadingSwitchLoading;
    
    //模拟网络请求延时,改变按钮状态  关闭-->打开
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        _loadSwitch.switchType = PAWFLoadingSwitchOn;
    });
}
-(void)vpnSwitchOnClicked{
    _loadSwitch.switchType = PAWFLoadingSwitchLoading;
    //模拟网络请求延时,改变按钮状态  打开-->关闭
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        _loadSwitch.switchType = PAWFLoadingSwitchOff;
    });
}
-(void)vpnSwitchLoadingClicked{
    NSLog(@"发请求");
}
@end
